package com.manong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manong.dao.NoticeMapper;
import com.manong.entity.ActionLog;
import com.manong.entity.Notice;
import com.manong.service.NoticeService;
import com.manong.vo.query.NoticeVo;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    /**
     * 分页查询通知列表
     * @param page
     * @param noticeVo
     * @return
     */
    @Override
    public IPage<Notice> findNoticeListByUsername(IPage<Notice> page, NoticeVo noticeVo) {
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<Notice>();
        queryWrapper.like(!ObjectUtils.isEmpty(noticeVo.getUsername()),"username",noticeVo.getUsername())
                .like(!ObjectUtils.isEmpty(noticeVo.getTitle()),"title",noticeVo.getTitle())
                .eq(!ObjectUtils.isEmpty(noticeVo.getValue()),"value",noticeVo.getValue())
                .orderByDesc("create_time");
        return baseMapper.selectPage(page,queryWrapper);
    }

    /**
     * 删除通知公告
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Long id) {

        return baseMapper.deleteById(id)>0;
    }
}
